package writers;

import java.util.Vector;

import javax.swing.JOptionPane;

import types.Menu;
import types.MenuBar;
import types.MenuItem;
import common.Settings;

public class MenuesWriter extends XMLWriter
{
	public MenuesWriter()
	{
		setFileName(Settings.MenuesOutputDirectory + Settings.MenuesXMLFile);
	}

	@Override
	public void write(Object data)
	{
		MenuBar bar = (MenuBar)data;
		Vector<Menu> menues = bar.getMenues();
		Vector<MenuItem> items = null;
		
		openFile();
		if(out!=null)
		{
			String str = "<Menues>\n";
			//=============================================
			for(int i=0;i<menues.size();i++)
			{
				items = menues.get(i).getItems();
				
				str += ("	<Menu text=\"" + menues.get(i).getText() + "\" level=\"" + menues.get(i).getLevel() + "\">\n");
				//========================
				for(int j = 0 ; j < items.size();j++)
				{
					str += ("		<Item level=\"" + items.get(j).getLevel() + "\" text=\"" + items.get(j).getText() + "\" Form=\"" + items.get(j).getFormName() + "\"/>\n");
				}
				//========================
				str += ("	</Menu>\n");
			}
			//=============================================
			str += ("</Menues>\n");
			
			writeToFile(str);
			closeFile();
		}
		else
		{
			JOptionPane.showMessageDialog(null, "Can't save xml file");
		}
	}
	
	

}
